package gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Insets;

import javax.swing.border.AbstractBorder;

/**
 * @author ARP
 */
public class LoweredBorder extends AbstractBorder{
    private static final long serialVersionUID = -8287912667820666578L;
    private static final Color defaultcolor = new Color(128, 128, 128);
    private Color topcolor;
    private Color bottomcolor;
    
    public LoweredBorder()    {
        this(null, null);
    }

    public LoweredBorder(Color topcolor, Color bottomcolor)    {
        this.topcolor = topcolor;
        this.bottomcolor = bottomcolor;
    }

    
    /**
     * tegn borderen
     */
    @Override
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
        g.translate(x, y); //offset kordinaterne med x,y
    
        g.setColor(topcolor == null ? defaultcolor : topcolor);
        g.drawLine(0, height - 1, 0, 0);
        g.drawLine(0, 0, width-1, 0);
    
        g.setColor(bottomcolor == null ? defaultcolor : bottomcolor);
        g.drawLine(width-1, 0, width-1, height - 1);
        g.drawLine(width-1, height - 1, 0, height - 1);
    
        g.translate(-x, -y); 
    }

    /**
     * returnere "tykkelsen" af borderen
     */
    @Override
    public Insets getBorderInsets(Component c)       {
        return new Insets(1, 1, 1, 1);
    }
}
